﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GenTheme.Theme;
using System.ComponentModel;
using System.Windows.Media;

namespace ThemesGenerator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public VThemeBinding VTheme = new VThemeBinding();

        public MainWindow()
        {
            InitializeComponent();

            this.ShowThemeFrame.DataContext = this.VTheme;

            this.VTheme.Value = new VisualTheme(new GenTheme.Parsing.Parser("6.bmp").Result);
        }

        private void ListBox_LostFocus(object sender, RoutedEventArgs e)
        {
            ((ListBox)sender).UnselectAll();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            SelectSize ss = new SelectSize();
            bool dResult = ss.ShowDialog() ?? false;
            if (dResult && ss.TSize != null)
            {
                this.VTheme.Value = new VisualTheme(ss.TSize.Width ?? 0, ss.TSize.Length ?? 0);
            }
        }

        private void ThemeObjectGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ((VisualThemeObject)((Grid)sender).DataContext).VTopThread.SetColor(this.ThemeObjectColorPicker.SelectedColor);
        }

        private void ThemeObjectGrid_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.ThemeObjectColorPicker.SelectedColor = ((VisualThread)((VisualThemeObject)((Grid)sender).DataContext).VTopThread).VThreadColor;
        }

        private void ShowThemeFrame_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource is ScrollViewer)
            {
                SolidColorBrush scb = this.ShowThemeFrame.Background as SolidColorBrush;
                this.ThemeObjectColorPicker.SelectedColor = scb.Color;
            }
        }
    }
}
